<?php

/**
 * Product filter form base class.
 *
 * @package    Onnobostro
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseProductFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'product_category_id'     => new sfWidgetFormDoctrineChoice(array('model' => 'ProductCategory', 'add_empty' => true)),
      'product_gift_id'         => new sfWidgetFormDmFilterInput(),
      'name'                    => new sfWidgetFormDmFilterInput(),
      'item_code'               => new sfWidgetFormDmFilterInput(),
      'description'             => new sfWidgetFormDmFilterInput(),
      'price'                   => new sfWidgetFormDmFilterInput(),
      'body_length'             => new sfWidgetFormDmFilterInput(),
      'half_chest_width'        => new sfWidgetFormDmFilterInput(),
      'special_rate'            => new sfWidgetFormDmFilterInput(),
      'discount_rate1'          => new sfWidgetFormDmFilterInput(),
      'discount_rate2'          => new sfWidgetFormDmFilterInput(),
      'gift_qty'                => new sfWidgetFormDmFilterInput(),
      'is_discount'             => new sfWidgetFormChoice(array('choices' => array('' => $this->getI18n()->__('yes or no', array(), 'dm'), 1 => $this->getI18n()->__('yes', array(), 'dm'), 0 => $this->getI18n()->__('no', array(), 'dm')))),
      'is_new'                  => new sfWidgetFormChoice(array('choices' => array('' => $this->getI18n()->__('yes or no', array(), 'dm'), 1 => $this->getI18n()->__('yes', array(), 'dm'), 0 => $this->getI18n()->__('no', array(), 'dm')))),
      'is_active'               => new sfWidgetFormChoice(array('choices' => array('' => $this->getI18n()->__('yes or no', array(), 'dm'), 1 => $this->getI18n()->__('yes', array(), 'dm'), 0 => $this->getI18n()->__('no', array(), 'dm')))),
      'image_id'                => new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'add_empty' => true)),
      'selling_qty'             => new sfWidgetFormDmFilterInput(),
      'created_at'              => new sfWidgetFormChoice(array('choices' => array(
        ''      => '',
        'today' => $this->getI18n()->__('Today'),
        'week'  => $this->getI18n()->__('Past %number% days', array('%number%' => 7)),
        'month' => $this->getI18n()->__('This month'),
        'year'  => $this->getI18n()->__('This year')
      ))),
      'updated_at'              => new sfWidgetFormChoice(array('choices' => array(
        ''      => '',
        'today' => $this->getI18n()->__('Today'),
        'week'  => $this->getI18n()->__('Past %number% days', array('%number%' => 7)),
        'month' => $this->getI18n()->__('This month'),
        'year'  => $this->getI18n()->__('This year')
      ))),
      'position'                => new sfWidgetFormDmFilterInput(),
      'created_by'              => new sfWidgetFormDoctrineChoice(array('model' => 'DmUser', 'add_empty' => true)),
      'updated_by'              => new sfWidgetFormDoctrineChoice(array('model' => 'DmUser', 'add_empty' => true)),
      'product_size_list_list'  => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'ProductSize')),
      'product_color_list_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'ProductColor')),
      'lr_articles_list'        => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'LrArticle')),
      'lr_newsletters_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'LrNewsletter')),
      'customar_orders_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CustomarOrder')),
      'medias_list'             => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'DmMedia')),
    ));

    $this->setValidators(array(
      'product_category_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('ProductCategory'), 'column' => 'id')),
      'product_gift_id'         => new sfValidatorPass(array('required' => false)),
      'name'                    => new sfValidatorPass(array('required' => false)),
      'item_code'               => new sfValidatorPass(array('required' => false)),
      'description'             => new sfValidatorPass(array('required' => false)),
      'price'                   => new sfValidatorPass(array('required' => false)),
      'body_length'             => new sfValidatorPass(array('required' => false)),
      'half_chest_width'        => new sfValidatorPass(array('required' => false)),
      'special_rate'            => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'discount_rate1'          => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'discount_rate2'          => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'gift_qty'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'is_discount'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_new'                  => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_active'               => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'image_id'                => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Image'), 'column' => 'id')),
      'selling_qty'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'              => new sfValidatorChoice(array('required' => false, 'choices' => array_keys($this->widgetSchema['created_at']->getOption('choices')))),
      'updated_at'              => new sfValidatorChoice(array('required' => false, 'choices' => array_keys($this->widgetSchema['updated_at']->getOption('choices')))),
      'position'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_by'              => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('CreatedBy'), 'column' => 'id')),
      'updated_by'              => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('UpdatedBy'), 'column' => 'id')),
      'product_size_list_list'  => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'ProductSize', 'required' => false)),
      'product_color_list_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'ProductColor', 'required' => false)),
      'lr_articles_list'        => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'LrArticle', 'required' => false)),
      'lr_newsletters_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'LrNewsletter', 'required' => false)),
      'customar_orders_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CustomarOrder', 'required' => false)),
      'medias_list'             => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmMedia', 'required' => false)),
    ));
    

    $this->widgetSchema->setNameFormat('product_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addProductSizeListListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.RelatedProductSize RelatedProductSize')
          ->andWhereIn('RelatedProductSize.size_id', $values);
  }

  public function addProductColorListListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.RelatedProductColor RelatedProductColor')
          ->andWhereIn('RelatedProductColor.color_id', $values);
  }

  public function addLrArticlesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.RelatedArticleProduct RelatedArticleProduct')
          ->andWhereIn('RelatedArticleProduct.article_id', $values);
  }

  public function addLrNewslettersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.RelatedLrNewsletterProduct RelatedLrNewsletterProduct')
          ->andWhereIn('RelatedLrNewsletterProduct.newsletter_id', $values);
  }

  public function addCustomarOrdersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.CustomarOrderProduct CustomarOrderProduct')
          ->andWhereIn('CustomarOrderProduct.customar_order_id', $values);
  }

  public function addMediasListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ProductDmMedia ProductDmMedia')
          ->andWhereIn('ProductDmMedia.dm_media_id', $values);
  }

  public function getModelName()
  {
    return 'Product';
  }

  public function getFields()
  {
    return array(
      'id'                      => 'Number',
      'product_category_id'     => 'ForeignKey',
      'product_gift_id'         => 'Text',
      'name'                    => 'Text',
      'item_code'               => 'Text',
      'description'             => 'Text',
      'price'                   => 'Text',
      'body_length'             => 'Text',
      'half_chest_width'        => 'Text',
      'special_rate'            => 'Number',
      'discount_rate1'          => 'Number',
      'discount_rate2'          => 'Number',
      'gift_qty'                => 'Number',
      'is_discount'             => 'Boolean',
      'is_new'                  => 'Boolean',
      'is_active'               => 'Boolean',
      'image_id'                => 'ForeignKey',
      'selling_qty'             => 'Number',
      'created_at'              => 'Date',
      'updated_at'              => 'Date',
      'position'                => 'Number',
      'created_by'              => 'ForeignKey',
      'updated_by'              => 'ForeignKey',
      'product_size_list_list'  => 'ManyKey',
      'product_color_list_list' => 'ManyKey',
      'lr_articles_list'        => 'ManyKey',
      'lr_newsletters_list'     => 'ManyKey',
      'customar_orders_list'    => 'ManyKey',
      'medias_list'             => 'ManyKey',
    );
  }
}
